package javolution.context;

import java.util.Map;
import javolution.util.FastMap;

/* loaded from: classes2.dex */
public class PersistentContext extends Context {
    private static PersistentContext _PersistentContext = new PersistentContext();
    private final FastMap _idToValue = new FastMap();

    /* loaded from: classes2.dex */
    public static class Reference<T> implements javolution.lang.Reference<T> {
        private static final FastMap INSTANCES = new FastMap();
        private final String _id;
        private T _value;

        /* JADX WARN: Multi-variable type inference failed */
        public Reference(String str, T t) {
            this._id = str;
            this._value = t;
            synchronized (INSTANCES) {
                if (INSTANCES.containsKey(str)) {
                    throw new IllegalArgumentException("Identifier " + str + " already in use");
                }
                INSTANCES.put(str, this);
            }
            if (PersistentContext._PersistentContext._idToValue.containsKey(str)) {
                set(PersistentContext._PersistentContext._idToValue.get(str));
            }
        }

        @Override // javolution.lang.Reference
        public T get() {
            return this._value;
        }

        protected void notifyChange() {
        }

        @Override // javolution.lang.Reference
        public void set(T t) {
            this._value = t;
            notifyChange();
        }

        /* JADX WARN: Code restructure failed: missing block: B:6:0x0010, code lost:
            if (((java.lang.Comparable) r3).compareTo(get()) < 0) goto L7;
         */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct code enable 'Show inconsistent code' option in preferences
        */
        public void setMaximum(T r3) {
            /*
                r2 = this;
                monitor-enter(r2)
                boolean r0 = r3 instanceof java.lang.Comparable     // Catch: java.lang.Throwable -> L36
                if (r0 == 0) goto L16
                java.lang.Object r0 = r2.get()     // Catch: java.lang.Throwable -> L36
                r1 = r3
                java.lang.Comparable r1 = (java.lang.Comparable) r1     // Catch: java.lang.Throwable -> L36
                int r0 = r1.compareTo(r0)     // Catch: java.lang.Throwable -> L36
                if (r0 >= 0) goto L2e
            L12:
                r2.set(r3)     // Catch: java.lang.Throwable -> L36
                goto L2e
            L16:
                boolean r0 = r3 instanceof java.lang.Integer     // Catch: java.lang.Throwable -> L36
                if (r0 == 0) goto L30
                java.lang.Object r0 = r2.get()     // Catch: java.lang.Throwable -> L36
                r1 = r3
                java.lang.Integer r1 = (java.lang.Integer) r1     // Catch: java.lang.Throwable -> L36
                int r1 = r1.intValue()     // Catch: java.lang.Throwable -> L36
                java.lang.Integer r0 = (java.lang.Integer) r0     // Catch: java.lang.Throwable -> L36
                int r0 = r0.intValue()     // Catch: java.lang.Throwable -> L36
                if (r1 >= r0) goto L2e
                goto L12
            L2e:
                monitor-exit(r2)     // Catch: java.lang.Throwable -> L36
                return
            L30:
                java.lang.IllegalArgumentException r3 = new java.lang.IllegalArgumentException     // Catch: java.lang.Throwable -> L36
                r3.<init>()     // Catch: java.lang.Throwable -> L36
                throw r3     // Catch: java.lang.Throwable -> L36
            L36:
                r3 = move-exception
                monitor-exit(r2)     // Catch: java.lang.Throwable -> L36
                goto L3a
            L39:
                throw r3
            L3a:
                goto L39
            */
            throw new UnsupportedOperationException("Method not decompiled: javolution.context.PersistentContext.Reference.setMaximum(java.lang.Object):void");
        }

        /* JADX WARN: Code restructure failed: missing block: B:6:0x0010, code lost:
            if (((java.lang.Comparable) r3).compareTo(get()) > 0) goto L7;
         */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct code enable 'Show inconsistent code' option in preferences
        */
        public void setMinimum(T r3) {
            /*
                r2 = this;
                monitor-enter(r2)
                boolean r0 = r3 instanceof java.lang.Comparable     // Catch: java.lang.Throwable -> L36
                if (r0 == 0) goto L16
                java.lang.Object r0 = r2.get()     // Catch: java.lang.Throwable -> L36
                r1 = r3
                java.lang.Comparable r1 = (java.lang.Comparable) r1     // Catch: java.lang.Throwable -> L36
                int r0 = r1.compareTo(r0)     // Catch: java.lang.Throwable -> L36
                if (r0 <= 0) goto L2e
            L12:
                r2.set(r3)     // Catch: java.lang.Throwable -> L36
                goto L2e
            L16:
                boolean r0 = r3 instanceof java.lang.Integer     // Catch: java.lang.Throwable -> L36
                if (r0 == 0) goto L30
                java.lang.Object r0 = r2.get()     // Catch: java.lang.Throwable -> L36
                r1 = r3
                java.lang.Integer r1 = (java.lang.Integer) r1     // Catch: java.lang.Throwable -> L36
                int r1 = r1.intValue()     // Catch: java.lang.Throwable -> L36
                java.lang.Integer r0 = (java.lang.Integer) r0     // Catch: java.lang.Throwable -> L36
                int r0 = r0.intValue()     // Catch: java.lang.Throwable -> L36
                if (r1 <= r0) goto L2e
                goto L12
            L2e:
                monitor-exit(r2)     // Catch: java.lang.Throwable -> L36
                return
            L30:
                java.lang.IllegalArgumentException r3 = new java.lang.IllegalArgumentException     // Catch: java.lang.Throwable -> L36
                r3.<init>()     // Catch: java.lang.Throwable -> L36
                throw r3     // Catch: java.lang.Throwable -> L36
            L36:
                r3 = move-exception
                monitor-exit(r2)     // Catch: java.lang.Throwable -> L36
                goto L3a
            L39:
                throw r3
            L3a:
                goto L39
            */
            throw new UnsupportedOperationException("Method not decompiled: javolution.context.PersistentContext.Reference.setMinimum(java.lang.Object):void");
        }

        public String toString() {
            return String.valueOf(get());
        }
    }

    public static PersistentContext getCurrent() {
        return _PersistentContext;
    }

    public static void setCurrent(PersistentContext persistentContext) {
        _PersistentContext = persistentContext;
        synchronized (Reference.INSTANCES) {
            FastMap.Entry head = Reference.INSTANCES.head();
            FastMap.Entry tail = Reference.INSTANCES.tail();
            while (true) {
                head = head.getNext();
                if (head != tail) {
                    Reference reference = (Reference) head.getValue();
                    if (persistentContext._idToValue.containsKey(reference._id)) {
                        reference.set(persistentContext._idToValue.get(reference._id));
                    }
                }
            }
        }
    }

    @Override // javolution.context.Context
    protected void enterAction() {
        throw new UnsupportedOperationException("Cannot enter persistent context (already in)");
    }

    @Override // javolution.context.Context
    protected void exitAction() {
        throw new UnsupportedOperationException("Cannot exit persistent context (always in)");
    }

    public Map<String, Object> getIdToValue() {
        return this._idToValue;
    }
}
